package com.csy.property.controller;


import cn.hutool.core.util.IdUtil;
import com.csy.commons.core.controller.BaseController;
import com.csy.commons.core.domain.BaseResponse;
import com.csy.commons.core.page.PageResult;
import com.csy.property.community.domain.AjBuilding;
import com.csy.property.entity.AjCommunityArea;
import com.csy.property.service.IAjCommunityAreaService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 小区分区 前端控制器
 * </p>
 *
 * @author 
 * @since 2025-03-05
 */
@RestController
@RequestMapping("/system/communityArea")
public class AjCommunityAreaController extends BaseController {

    @Resource
    private IAjCommunityAreaService ajCommunityAreaService;

    @GetMapping("/queryPullDownArea")
    public BaseResponse pullDownList(AjCommunityArea communityArea){
        List<AjCommunityArea> ajCommunityAreas = ajCommunityAreaService.getAreaList(communityArea);
        return BaseResponse.success(ajCommunityAreas);
    }

    @GetMapping("/list")
    public PageResult list(AjCommunityArea communityArea){
        startPage();
        List<AjCommunityArea> list = ajCommunityAreaService.getAreaList(communityArea);
        return getData(list);
    }

    @GetMapping("/{id}")
    public BaseResponse getById(@PathVariable("id") String id){

        return BaseResponse.success(ajCommunityAreaService.getById(id));
    }
    @PostMapping
    public BaseResponse add(@RequestBody AjCommunityArea ajCommunityArea){
        ajCommunityArea.setId(IdUtil.getSnowflakeNextId());
        boolean b = ajCommunityAreaService.save(ajCommunityArea);
        return toAjax(b == true ? 1 : 0);
    }

    @PutMapping
    public BaseResponse update(@RequestBody AjCommunityArea ajCommunityArea){

        boolean b = ajCommunityAreaService.updateById(ajCommunityArea);
        return toAjax(b == true ? 1 : 0);
    }
    @DeleteMapping("/{id}")
    public BaseResponse del(@PathVariable("id")String id){
        boolean b = ajCommunityAreaService.removeById(id);
        return toAjax(b == true ? 1 : 0);
    }








}
